<% 
#locals
article=single||article 

#cache tag
tag=@tag
begin
  tag = Tag.find(article.tag_id) if tag.nil?
rescue
end

#cached person
person=@person || article.person

#increase view counts
if logged_in? && ( current_person?(person))
	article.view_count=article.view_count.to_i+1
	article.save
end
%>

      <table class="ContentBlock" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td align="left" valign="top">
          <a href="<%= cat_blog_path(@cat_id,article.id) %>">
          	<% unless article.media_url.blank? %>
	<img alt="" title="" border="0"  src="<%=h article.media_url%>">
	<% end %>
          </a>
          <%- unless tag.nil? -%>
          <a class="ContentLable" href='<%= blogs_cat_tag_path(@cat_id,article.tag_id) %>'><%=h tag.name %></a>
          <%- end -%>
              <h3><a href="<%= cat_blog_path(@cat_id,article.id) %>" class="ContentTitle"><%= h(article.title) %></a></h3>
          <%= textilize article.body%></td>
          <td width="300" align="left" valign="top"><dl>
    <%- if logged_in? && ( current_person?(person)||current_person.admin?) -%>
      <dt> <%= link_to "Edit", edit_cat_blog_path(@cat_id,article) %>
      | <%= link_to "Delete", blog_path(article),
                              :method => :delete %>
      </dt>
    <%- end -%>
            <dt>Posted <%= time_ago_in_words article.created_at  %></dt>
            <dt>By <a href="<%=blogs_cat_person_path(@cat_id,person)%>" class="blue"><%= person.name %></a></dt>

            <dt><a href="<%= cat_blog_path(@cat_id,article.id) %>" class="blue"><%= article.view_count %></a> views, <a href="<%= cat_blog_path(@cat_id,article.id) %>#comments" class="blue"><%= "#{article.article_comments_count}" %></a> Comments</dt>
          </dl></td>
        </tr>
      </table>

<a href='comments'></a>
  <h4>Comments</h4>
    <ul class="list comments full" ><span id='comments'></span>
  <%- unless article.article_comments_count==0 -%>
      <%= render :partial => 'article_comments/display', :collection => article.article_comments %>
  <%- end -%>
    </ul>
 
 <%- if logged_in? -%>
<script language=javascript>
function add_comment()
{
  var a=$('article_comment_body').value.strip();
  if(a.length>0)
  {
	$('article_comment_body').value=a;
	return true;
  }
  return false;
}
</script>
<h4>Leave a comment</h4>

<%
 article_comment = ArticleComment.new
 article_comment.article_id=article.id
 article_comment.person_id = current_person.id

 %>
 <% form_for(article_comment) do |f| %>
  <%= f.hidden_field :article_id %>
  <%= f.hidden_field :person_id %>
  <p>Body:<br /><%= f.text_area :body, :rows => 5, :cols => 90 %></p>
  <%= link_to_remote "Add a comment", 
   :url => {:controller=>'article_comments',:action => "add"},:method=>:post,:submit   => "new_article_comment",:condition =>"add_comment()"  %>
 <% end %>
<%- end -%>